﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Api.Filter;
using Customer.Bussiness_Service;
using Entity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ServiceCore;

namespace Customer.Areas.rk_question.Controllers
{
     
    [ApiController, Area("rk_question"), Route("/question/[action]"), RK_Admin]
    public class questionController : ControllerBase
    {
        private readonly Iquestion_service _service;
        private readonly IToole_DI _tool;
        public questionController(Iquestion_service service, IToole_DI tool)
        {
            _service = service;
            _tool = tool;
        }
        #region 题库
        /// <summary>
        ///  保存题目信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultObjModel save(save_question query)
        {
            var result = _service.save(query);
            _tool.di_es.Add_Log($"question==>录入题库{Newtonsoft.Json.JsonConvert.SerializeObject(query)}=>{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "question");
            return result;
        }
        /// <summary>
        ///  获取补货详情分页列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultListModel<question_body_searchshow> get_pagelist(get_question_query query)
        {
            var result = _service.get_question_pagelist(query);
            return result;
        }
        /// <summary>
        ///  修改题目状态
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel change_state(string question_id, question_state? question_state)
        {
            var result = _service.change_state(question_id, question_state);
            _tool.di_es.Add_Log($"change_state==>修改题目状态{Newtonsoft.Json.JsonConvert.SerializeObject(new { question_id, question_state })}=>{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "question");
            return result;
        }
        /// <summary>
        ///  删除题目
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel del(string question_id)
        {
            var result = _service.del(question_id);
            _tool.di_es.Add_Log($"del==>删除题目{Newtonsoft.Json.JsonConvert.SerializeObject(new { question_id })}=>{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "question");
            return result;
        }
        /// <summary>
        ///  获取题目详情
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel get_question_model(string question_id)
        {
            var result = _service.get_question_model(question_id);
            return result;
        }
        #endregion

        #region 答题用户
        /// <summary>
        ///  获取答题人员列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultListModelWithObj<question_user_search> get_question_user_pagelist(user_search query)
        {
            var result = _service.get_question_user_pagelist(query);
            return result;
        }
        /// <summary>
        ///  保存答题人员
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultModel save_question_user(question_user model)
        {
            var result = _service.save_question_user(model);
            _tool.di_es.Add_Log($"save_question_user==>保存答题人员{Newtonsoft.Json.JsonConvert.SerializeObject(model)}=>{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "question");
            return result;
        }
        /// <summary>
        ///  设置答题用户可用/禁用状态
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel set_question_use_state(string uid, bool? isuse)
        {
            var result = _service.set_question_use_state(uid, isuse);
            _tool.di_es.Add_Log($"set_question_use_state==>设置答题用户可用/禁用状态{Newtonsoft.Json.JsonConvert.SerializeObject(new { uid, isuse })}=>{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "question");
            return result;
        }
        /// <summary>
        ///  删除用户
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel del_question_user(string uid)
        {
            var result = _service.del_question_user(uid);
            _tool.di_es.Add_Log($"del_question_user==>删除用户{Newtonsoft.Json.JsonConvert.SerializeObject(new { uid })}=>{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "question");
            return result;
        } 
        /// <summary>
        ///  导入模板下载
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public void question_user_template_down()
        {
            _service.question_user_template_down();
        }
        /// <summary>
        ///  批量导入答题用户信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultObjModel upload_user(IFormFileCollection files)
        {
            var result = _service.upload_user(files);
            _tool.di_es.Add_Log($"upload_user==>批量导入=>{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "question");
            return result;
        }
        /// <summary>
        ///  导出用户数据
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public void question_user_down([FromForm]user_search query)
        {
            _service.question_user_down(query); 
        } 
        /// <summary>
        /// 设置每人每天答题次数
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultObjModel set_baseuser_answer_count(int? count)
        {
            var result = _service.set_baseuser_answer_count(count);
            _tool.di_es.Add_Log($"set_baseuser_answer_count==>设置每人每天答题次数=>{Newtonsoft.Json.JsonConvert.SerializeObject(new { count })}=>{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "question");
            return result;
        }
        #endregion

        #region 策略
        /// <summary>
        ///  添加策略
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultModel save_question_strategy(save_question_strategy model)
        {
            var result = _service.save_question_strategy(model);
            _tool.di_es.Add_Log($"save_question_strategy==>保存策略=>{Newtonsoft.Json.JsonConvert.SerializeObject(model)}=>{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "question");
            return result;
        }
        /// <summary>
        /// 获取题目策略列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultListModel<question_strategy_for_search> get_question_strategy_pagelist(question_strategy_search query)
        {
            var result = _service.get_question_strategy_pagelist(query);
            return result;
        }
        /// <summary>
        /// 删除题目策略列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public ResultModel del_question_strategy(string strategy_id)
        {
            var result = _service.del_question_strategy(strategy_id);
            _tool.di_es.Add_Log($"del_question_strategy==>删除题目策略列表=>{Newtonsoft.Json.JsonConvert.SerializeObject(new { strategy_id })}=>{Newtonsoft.Json.JsonConvert.SerializeObject(result)}", "question");
            return result;
        }
        #endregion
        #region 答题记录查询
        /// <summary>
        /// 答题记录查询
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultListModel<quertion_order_search_item> get_question_order_pagelist(quertion_order_query query)
        {
            var result = _service.get_question_order_pagelist(query);
            return result;
        }
        #endregion
    }
}